<%--
  Created by IntelliJ IDEA.
  User: apple
  Date: 2022/4/26
  Time: 3:41 下午
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath()+"/";%>
<!doctype html>
<html>
<head>
    <base href="<%=path%>">
    <title>用户新增/编辑</title>
    <link href="css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
    <link href="css/plugins/switchery/switchery.css" rel="stylesheet">
</head>
<style>
    .error{
        color: red;
        position: absolute;
        line-height:40px;
        right:0px;
    }
</style>
<body style="overflow-x: hidden">
<form class="form-horizontal" id="objectForm">
    <input type="hidden" name="id" value="${resource.id}"/>
    <div class="form-group">
        <div class="col-sm-12">
            <label for="parentId" class="col-sm-4 control-label">上级资源：</label>
            <div class="col-sm-8">
                <input type="hidden" name="parentId" id="parentId" value="${resource.parentId}">
                <input type="text" id="parentName" class="form-control" placeholder="Search for..." value="${parentName}" onclick="showTree();" style="width: 60%;float:left">
                <span class="input-group-btn">
                    <button class="btn btn-default" type="button" onclick="showTree();"><i class="glyphicon glyphicon-search"></i></button>
                </span>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <label for="deptName" class="col-sm-4 control-label">菜单类型</label>
            <div class="col-sm-8">
                <label class="checkbox-inline">
                    <input type="radio" name="resourceType" <c:if test="${resource.resourceType==0}">checked</c:if> value="0"> 目录
                </label>
                <label class="checkbox-inline">
                    <input type="radio" name="resourceType" <c:if test="${resource.resourceType==1}">checked</c:if> value="1"> 菜单
                </label>
                <label class="checkbox-inline">
                    <input type="radio" name="resourceType" <c:if test="${resource.resourceType==2}">checked</c:if> value="2"> 按钮
                </label>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <label for="deptName" class="col-sm-4 control-label">*资源名称</label>
            <div class="col-sm-8">
                <input type="text"  class="form-control" name="resourceName" value="${resource.resourceName}" id="deptName" placeholder="部门名称">

            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <label for="orderNum" class="col-sm-4 control-label">请求地址</label>
            <div class="col-sm-8">
                <input type="text"  class="form-control" name="url" value="${resource.url}" id="orderNum" placeholder="请求地址">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <label class="col-sm-4 control-label">打开方式</label>
            <div class="col-sm-8">
                <select name="target" class="form-control">
                    <option value="0">页签</option>
                </select>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <label  class="col-sm-4 control-label">权限标识</label>
            <div class="col-sm-8">
                <input type="text"  class="form-control"  name="permission" value="${resource.permission}" placeholder="权限">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <label  class="col-sm-4 control-label">*显示顺序</label>
            <div class="col-sm-8">
                <input type="text"  class="form-control"  name="shortNum" value="${resource.shortNum}" placeholder="显示顺序">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <label  class="col-sm-4 control-label">图标</label>
            <div class="col-sm-8">
                <input type="text"  class="form-control"  name="icon" value="${resource.icon}" placeholder="图标">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <label  class="col-sm-4 control-label">状态</label>
            <div class="col-sm-8">
                <select name="status" class="form-control">
                    <option value="0">正常</option>
                    <option value="1">停用</option>
                </select>
            </div>
        </div>
    </div>
    <div class="form-group" >
        <div class="col-sm-4"></div>
        <div class="col-sm-8" style="align:center">
            <button type="button" class="btn btn-warning" onclick="save();"><i class="glyphicon glyphicon-saved"></i>保存</button>
            <button type="reset" class="btn btn-warning"><i class="glyphicon glyphicon-refresh"></i>重置</button>
        </div>
    </div>
</form>
</body>
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.7"></script>
<script src="js/plugins/layer/layer.min.js"></script>
<script src="js/plugins/validate/jquery.validate.min.js"></script>
<script src="js/plugins/validate/messages_zh.min.js"></script>
<!-- Switchery -->
<script src="js/plugins/switchery/switchery.js"></script>
<script src="js/sofwin.js"></script>
<script>
    var elem = document.querySelector('.js-switch');
    var switchery = new Switchery(elem);
    // 给当前form表单添加了表单验证规则
    $("form").validate({
        rules:{
            resourceName:{
                required:true
            },
            orderNum:{
                required:true
            }
        },
        messages:{
            "resourceName":{
                required: '资源名称不能为空'
            },
            "orderNum":{
                required:'显示顺序不能为空'
            }
        }
    });
    function save(){
        if(!$("form").valid()){
            // true验证规则全部成功
            return;
        }
        $.operator.post('resource/save',$("form").serialize());
    }
    function showTree(){
        $.modal.addWinBtns('选择上级资源','resource/tree',['400px','400px'],function(index, layero){
            var body = layer.getChildFrame('body', index);
            var iframeWin = window[layero.find('iframe')[0]['name']];
            iframeWin.setParentValue();
            // document..contentWindow.setParentValue();
        });
    }
    function close(){
        layer.close(index);
    }

    function setParent(deptName,deptId){
        $("#parentId").val(deptId);
        $("#parentName").val(deptName);
    }
</script>
</html>
